/**
 * Project: drink-maker-proj
 * Package: com.made2ordersoftware.drinkmaker.domain
 * File: DrinkIngredientEntity.java
 * Created: May 10, 2014
 */
/**
 * Copyright (c) 2010 Made 2 Order Software, LLC
 *
 * All rights reserved. No part of this software may be reproduced, stored in a retrieval system, or
 * transmitted in any form or by any means, without the prior written permission of Made 2 Order Software.
 *
 * You may not distribute the URL or redistribute the files to third parties. You may transfer the files onto
 * a single storage device so long as you can prove ownership of the software. You may not reverse engineer,
 * decompile, or disassemble the software or media files. You may not modify or translate the software or
 * media, or distribute copies of the software or media without the written consent of Made 2 Order Software,
 * LLC.
 */
package com.made2ordersoftware.drinkmaker.domain;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author David
 * @version 1.0.0
 */
@Entity
@Table(name = "drink_ingredient")
@XmlRootElement
@NamedQueries({@NamedQuery(name = "DrinkIngredientEntity.findAll",
            query = "SELECT d FROM DrinkIngredientEntity d"),
    @NamedQuery(name = "DrinkIngredientEntity.findByDrinkId",
            query = "SELECT d FROM DrinkIngredientEntity d WHERE d.drinkIngredientEntityPK.drinkId = :drinkId"),
    @NamedQuery(name = "DrinkIngredientEntity.findByIngredientId",
            query
            = "SELECT d FROM DrinkIngredientEntity d WHERE d.drinkIngredientEntityPK.ingredientId = :ingredientId"),
    @NamedQuery(name = "DrinkIngredientEntity.findByAmount",
            query = "SELECT d FROM DrinkIngredientEntity d WHERE d.amount = :amount")})
public class DrinkIngredientEntity implements Serializable {

    private static final long serialVersionUID = 1L;
    private static final Logger LOG = LoggerFactory.getLogger(DrinkIngredientEntity.class);
    @EmbeddedId
    protected DrinkIngredientEntityPK drinkIngredientEntityPK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    private String amount;
    @JoinColumn(name = "drink_id", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private DrinkEntity drink;
    @JoinColumn(name = "ingredient_id", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private IngredientEntity ingredient;

    public DrinkIngredientEntity() {
    }

    public DrinkIngredientEntity(IngredientEntity ingredient, String amount) {
        this.ingredient = ingredient;
        this.amount = amount;
    }

    public DrinkIngredientEntity(DrinkIngredientEntityPK drinkIngredientEntityPK) {
        this.drinkIngredientEntityPK = drinkIngredientEntityPK;
    }

    public DrinkIngredientEntity(DrinkIngredientEntityPK drinkIngredientEntityPK, String amount) {
        this.drinkIngredientEntityPK = drinkIngredientEntityPK;
        this.amount = amount;
    }

    public DrinkIngredientEntity(long drinkId, long ingredientNamesId) {
        this.drinkIngredientEntityPK = new DrinkIngredientEntityPK(drinkId, ingredientNamesId);
    }

    // <editor-fold defaultstate="collapsed" desc="getters-setters">
    public DrinkIngredientEntityPK getDrinkIngredientEntityPK() {
        return drinkIngredientEntityPK;
    }

    public void setDrinkIngredientEntityPK(DrinkIngredientEntityPK drinkIngredientEntityPK) {
        this.drinkIngredientEntityPK = drinkIngredientEntityPK;
    }

    public String getAmount() {
        return amount;
    }

    public void setAmount(String amount) {
        this.amount = amount;
    }

    public DrinkEntity getDrink() {
        return drink;
    }

    public void setDrink(DrinkEntity drink) {
        this.drink = drink;
    }

    public IngredientEntity getIngredient() {
        return ingredient;
    }

    public void setIngredient(IngredientEntity ingredient) {
        this.ingredient = ingredient;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="hash-equal-tostring">
    @Override
    public int hashCode() {
        int hash = 19;
        hash += (drinkIngredientEntityPK != null ? drinkIngredientEntityPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof DrinkIngredientEntity)) {
            return false;
        }
        DrinkIngredientEntity other = (DrinkIngredientEntity) object;
        return (this.drinkIngredientEntityPK != null || other.drinkIngredientEntityPK == null)
                && (this.drinkIngredientEntityPK == null || this.drinkIngredientEntityPK.equals(
                        other.drinkIngredientEntityPK));
    }

    @Override
    public String toString() {
        return "com.made2ordersoftware.drinkmaker.domain.DrinkIngredientEntity[ drinkIngredientEntityPK="
                + drinkIngredientEntityPK + " ]";
    }
    // </editor-fold>

}
